const { expect, use } = require('chai');
const { BigNumber } = require('ethers');
const { deployContract, MockProvider, solidity } = require('ethereum-waffle');
const { ethers, upgrades } = require("hardhat");

use(solidity);

describe("Test Lottery.randomNFT Interface", function () {
    var OWNER;
    var BindBoxAddress;
    var Lottery;
    var BlindBoxRarityPR = [{name: "SR", PR: 1200, enumId: 1, totalSupply:2000, issued:0 },
                            {name: "SSR", PR: 2000, enumId: 2, totalSupply:2000, issued:0 },
                            {name: "UR", PR: 4000, enumId: 3, totalSupply:2000, issued:0 }
                            ];

    beforeEach(async () => {
        [OWNER, BindBoxAddress] = await ethers.getSigners();
        const randomContractPauser = await ethers.getContractFactory("Lottery", OWNER);
        Lottery = await upgrades.deployProxy(randomContractPauser, [10000], {initializer:"__Lottery_init"});
        await Lottery.deployed();
    });


    it("Should be set _BindBox successful;", async function () {
        var setBindBox = await Lottery.connect(OWNER).setBindBox(BindBoxAddress.address);
        await setBindBox.wait();

        var receipt = await ethers.provider.getTransactionReceipt(setBindBox.hash);
        expect(receipt.status).to.equal(1);
    });

    it("should be set BindBoxRarityPR successful;", async function () {
        var addBlindBoxRarityPR = await Lottery.connect(OWNER).addBlindBoxRarityPR(1,BlindBoxRarityPR);
        await addBlindBoxRarityPR.wait();

        var receipt = await ethers.provider.getTransactionReceipt(addBlindBoxRarityPR.hash);
        expect(receipt.status).to.equal(1);
    });

    it("should be set editBlindBoxRarityPR successful;", async function () {
        var addBlindBoxRarityPR = await Lottery.connect(OWNER).addBlindBoxRarityPR(1,BlindBoxRarityPR);
        await addBlindBoxRarityPR.wait();

        var editBlindBoxRarityPR = await Lottery.connect(OWNER).editBlindBoxRarityPR(1,1,50);
        await editBlindBoxRarityPR.wait();

        var receipt = await ethers.provider.getTransactionReceipt(editBlindBoxRarityPR.hash);
        expect(receipt.status).to.equal(1);
    });

    it("should be rand box successful;", async function () {
        var setBindBox = await Lottery.connect(OWNER).setBindBox(OWNER.address);
        await setBindBox.wait();

        var addBlindBoxRarityPR1 = await Lottery.connect(OWNER).addBlindBoxRarityPR(1,BlindBoxRarityPR);
        await addBlindBoxRarityPR1.wait();
        var addBlindBoxRarityPR2 = await Lottery.connect(OWNER).addBlindBoxRarityPR(2,BlindBoxRarityPR);
        await addBlindBoxRarityPR2.wait();
        var addBlindBoxRarityPR3 = await Lottery.connect(OWNER).addBlindBoxRarityPR(3,BlindBoxRarityPR);
        await addBlindBoxRarityPR3.wait();
        var addBlindBoxRarityPR4 = await Lottery.connect(OWNER).addBlindBoxRarityPR(4,BlindBoxRarityPR);
        await addBlindBoxRarityPR4.wait();
        var randm11 = await Lottery.connect(OWNER).randomNFT(1);
        await randm11.wait();

        var randm12 = await Lottery.connect(OWNER).randomNFT(2);
        await randm12.wait();

        var randm13= await Lottery.connect(OWNER).randomNFT(3);
        await randm13.wait();

        var randm1 = await Lottery.connect(OWNER).randomNFT(4);
        await randm1.wait();
        var randm2 = await Lottery.connect(OWNER).randomNFT(4);
        await randm2.wait();
        var randm3 = await Lottery.connect(OWNER).randomNFT(4);
        await randm3.wait();
        var randm4 = await Lottery.connect(OWNER).randomNFT(4);
        await randm4.wait();
        var randm5 = await Lottery.connect(OWNER).randomNFT(4);
        await randm5.wait();
        var randm6 = await Lottery.connect(OWNER).randomNFT(4);
        await randm6.wait();
        var receipt = await ethers.provider.getTransactionReceipt(randm1.hash);
        expect(receipt.status).to.equal(1);


    })
});
